﻿using Castle.Core.Internal;
using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_ScheduleController : BaseApiController
    {
        #region DI

        public PB_ScheduleController(IPB_ScheduleBusiness pB_ScheduleBus)
        {
            _pB_ScheduleBus = pB_ScheduleBus;
        }

        IPB_ScheduleBusiness _pB_ScheduleBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_Schedule>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_ScheduleBus.GetDataListAsync(input);
        }
        /// <summary>
        /// 查询结果集-联合查询返回部门名称和车间名称
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_ScheduleDTO>> GetDataListShowDeptName(PageInput<PB_ScheduleConditionDTO> input)
        {
            return await _pB_ScheduleBus.GetDataListDTO(input);
        }
        [HttpPost]
        public async Task<PageResult<PB_ScheduleDTO>> GetDataListToexamineAsync(PageInput<PB_ScheduleConditionDTO> input)
        {
            return await _pB_ScheduleBus.GetDataListToexamineAsync(input);
        }
        [HttpPost]
        public async Task<PB_Schedule> GetTheData(IdInputDTO input)
        {
            return await _pB_ScheduleBus.GetTheDataAsync(input.id);
        }
        [HttpPost]
      public  async Task ToExamineDataAsync(string id, int stateType) {
            await _pB_ScheduleBus.ToExamineDataAsync(id,stateType);
        }
        /// <summary>
        /// 根据生产排班id查询生产排班明细信息 
        /// </summary>
        /// <param name="ParentId">排班id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ScheduleList> GetDataListInfo(string ParentId)
        {
            var res = await _pB_ScheduleBus.GetDataListInfo(ParentId);
            return res;
        }
        /// <summary>
        /// 保存 生产排班 及生产排班明细
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SavalistData(Entity.DTO.PB_ScheduleListDTO data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                await _pB_ScheduleBus.AddData(data);
            }
            else
            {
                InitEntity(data);
                await _pB_ScheduleBus.AddData(data);
            }
        }
        /// <summary>
        /// 排班审核
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UpdateDataStateAsync(string Id) {
            await _pB_ScheduleBus.UpdateDataStateAsync(Id);
        }
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_Schedule data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ScheduleBus.AddDataAsync(data);
            }
            else
            {
                await _pB_ScheduleBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_ScheduleBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}